<!DOCTYPE html>
<html>
	<head>
		<title>Using Web Worker (non-blockin UI)</title>
		<link rel="stylesheet" href="../../codebase/webix/webix.css" type="text/css" charset="utf-8">
		<script src="../../codebase/webix/webix.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" href="../../codebase/pivot.css" type="text/css" charset="utf-8">
		<script src="../../codebase/pivot.js" type="text/javascript" charset="utf-8"></script>

		<link rel="stylesheet" href="../common/samples.css" type="text/css" charset="utf-8">
		<script src="../common/testdata.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div class='header_comment'>Aborting long processing</div>
		<div id="testA"></div>

		<style type="text/css">
			html, body {
				width: 100%;
				height: 100%;
				padding: 0;
				margin: 0;
			}
		</style>

		<script type="text/javascript" charset="utf-8">

		var bad_dataset = [];
		for (var i=1; i<200; i++)
			for (var j=1; j<100; j++)
				for (var k=1; k<2; k++) 
					bad_dataset.push({ a:i, b:j, c:k, d:i, e:j, f:k,  });

		function runSlowTask(){
			$$("pivot").setStructure({
				"rows":["a"],
				"columns":["b", "d", "e", "f"],
				"values":[
					{"name":"c","text":"oil","operation":["min","sum"]}
				],
				"filters":[]
			});
		}

		function runFastTask(){
			$$("pivot").setStructure({
				"rows":["a"],
				"columns":["b"],
				"values":[
					{"name":"c","text":"oil","operation":["min","sum"]}
				],
				"filters":[]
			});
		}

		webix.debug_pivot = true;

		webix.ready(function(){
			webix.ui({
				margin:30, 
				rows: [
					{
						container:"testA",
						id:"pivot", view:"pivot",

						ping:function(start){
							var now = (new Date()).valueOf();
							//break if processing is longer than 3 seconds 
							if (now - start > 3*1000){
								alert("Too complex parameters, aborting");
								throw new Error("Aborting...");
							}
						},

						height:400, width:1000,
						data: bad_dataset,
						max: true
					},
					{ cols:[
						{ view:"button", value:"Build Pivot (fast)", inputWidth:200, align:"center", click: runFastTask },
						{ view:"button", value:"Build Pivot (slow)", inputWidth:200, align:"center", click: runSlowTask }
					]}
				]
			});

		});
		</script>
	</body>
</html>